package thread.threaddemo;

import java.util.concurrent.TimeUnit;

/**
 * @Author: wenjingyuan
 * @Date: 2022/11/12/17:29
 * @Description:打印线程的几种状态
 */
public class ThreadState {
    public static void main(String[] args) throws InterruptedException {
        //printState();
        Thread t1=new Thread(()->{
            System.out.println("当前线程的状态1："+Thread.currentThread().getState());
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        //未启动之前先查看线程状态
        System.out.println("当前线程状态2："+t1.getState());
        t1.start();
        //让主线程休眠
        Thread.sleep(1000);
        System.out.println("当前线程状态3："+t1.getState());
        //等到t1执行结束以后
        t1.join();
        System.out.println("当前线程执行状态4:"+t1.getState());
    }

    private static void printState() {
        for(Thread.State item: Thread.State.values()){
            System.out.println(item);
        }
    }
}
